﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpMap.Presentation.Views;

namespace SharpMap.Presentation.Wpf
{
    public static class MapViewsManager
    {
        static Dictionary<Map, HashSet<IView>> _viewsRegistry;
        static Dictionary<Map, IView> _defalutViewsRegistry;
 
        //currnetly unused
        private static void RegisterMapView(Map map, IView view)
        {
            HashSet<IView> views;
            if(!_viewsRegistry.TryGetValue(map,out views))
            {
                views = new HashSet<IView>();
                _viewsRegistry.Add(map,views);
            }
            views.Add(view);
        }
        
        //currnetly unused
        public static void UnregisterMapView(Map map, IView view)
        {
            HashSet<IView> views;

            if (!_viewsRegistry.TryGetValue(map, out views))
            {
                 return;
            }
            views.Remove(view);
            if (views.Count == 0)
            {
                _viewsRegistry.Remove(map);
            }
        }

        private static void RegisterMapDefaultView(Map map, IView view)
        {
            _defalutViewsRegistry.Add(map,view);
        }

        //currnetly unused
        public static void UnregisterMapDefaultView(Map map, IView view)
        {
            _defalutViewsRegistry.Remove(map);
        }

        public static IView GetDefalutView(Map map)
        {
            return _defalutViewsRegistry[map];
        }
    }
}
